/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isd.seguridad.modelo;

import com.isd.inventario.modelo.Producto;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Claudio
 */
@Entity
@Table(name = "USR_TVPRFA", schema = "dbo")
@IdClass(ProductoFavoritoPK.class)
public class ProductoFavorito implements Serializable {
          
    @Id    
    @Column(name = "USR_TVPRFA_USUARI", nullable = false, length = 13)
    private String usuari;    
    @Id
    @Column(name = "USR_TVPRFA_TIPPRO", nullable = false, length = 6)
    @OrderBy
    private String tippro;
    @Id
    @Column(name = "USR_TVPRFA_ARTCOD", nullable = false, length = 30)
    @OrderBy
    private String artcod;
        
    //Cliente
    @JoinColumn(name = "USR_TVPRFA_USUARI", referencedColumnName = "USR_USUWEB_NOMBRE", nullable = false, insertable=false, updatable=false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Usuario usuario;
    
    @JoinColumns({
        @JoinColumn(name = "USR_TVPRFA_TIPPRO", referencedColumnName = "STMPDH_TIPPRO", nullable = false, insertable=false, updatable=false),
        @JoinColumn(name = "USR_TVPRFA_ARTCOD", referencedColumnName = "STMPDH_ARTCOD", nullable = false, insertable=false, updatable=false)
    })
    @ManyToOne(optional=false)
    private Producto producto;
    
//    @Column(name = "USR_TVPRFA_PRECIO", precision = 10, scale = 4)
//    private BigDecimal precioFinal;
//    
//    @Column(name = "USR_TVPRFA_VARPRE", length = 1)
//    private String conVariacionPrecio; 
//    
//    @Column(name = "USR_TVPRFA_ARTCOD", length = 6)
//    private String moneda;
    
    @Column(name = "USR_TV_FECALT")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecalt;
    @Column(name = "USR_TV_FECMOD")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecmod;
    @Column(name = "USR_TV_USERID", length = 15)
    private String userId;
    @Column(name = "USR_TV_ULTOPR", length=1)
    private String ultopr;
    @Column(name = "USR_TV_DEBAJA", length=1)
    private String debaja;
    @Column(name = "USR_TV_OALIAS", length = 10)
    private String oalias;
    
    @Transient
    private boolean seleccionado;
   

    public ProductoFavorito() {
        
        this.fecalt = new Date();
        this.fecmod = new Date();
        this.userId = "TV";
        this.ultopr = "A";
        this.debaja = "N";
        this.oalias = "USR_TVPRFA";
        
    }

    public ProductoFavorito(String usuari, String tippro, String artcod) {
        this.usuari = usuari;
        this.tippro = tippro;
        this.artcod = artcod;
        
        this.fecalt = new Date();
        this.fecmod = new Date();
        this.userId = "TV";
        this.ultopr = "A";
        this.debaja = "N";
        this.oalias = "USR_TVPRFA";
                
    }

    public String getUsuari() {
        return usuari;
    }

    public void setUsuari(String usuari) {
        this.usuari = usuari;
    }

    public String getTippro() {
        return tippro;
    }

    public void setTippro(String tippro) {
        this.tippro = tippro;
    }

    public String getArtcod() {
        return artcod;
    }

    public void setArtcod(String artcod) {
        this.artcod = artcod;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Producto getProducto() {
        return producto;
    }

    public void setProducto(Producto producto) {
        this.producto = producto;
    }

    public Date getFecalt() {
        return fecalt;
    }

    public void setFecalt(Date fecalt) {
        this.fecalt = fecalt;
    }

    public Date getFecmod() {
        return fecmod;
    }

    public void setFecmod(Date fecmod) {
        this.fecmod = fecmod;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUltopr() {
        return ultopr;
    }

    public void setUltopr(String ultopr) {
        this.ultopr = ultopr;
    }

    public String getDebaja() {
        return debaja;
    }

    public void setDebaja(String debaja) {
        this.debaja = debaja;
    }

    public String getOalias() {
        return oalias;
    }

    public void setOalias(String oalias) {
        this.oalias = oalias;
    }

    public boolean isSeleccionado() {
        return seleccionado;
    }

    public void setSeleccionado(boolean seleccionado) {
        this.seleccionado = seleccionado;
    }
   
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 97 * hash + (this.usuari != null ? this.usuari.hashCode() : 0);
        hash = 97 * hash + (this.tippro != null ? this.tippro.hashCode() : 0);
        hash = 97 * hash + (this.artcod != null ? this.artcod.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProductoFavorito other = (ProductoFavorito) obj;
        if ((this.usuari == null) ? (other.usuari != null) : !this.usuari.equals(other.usuari)) {
            return false;
        }
        if ((this.tippro == null) ? (other.tippro != null) : !this.tippro.equals(other.tippro)) {
            return false;
        }
        if ((this.artcod == null) ? (other.artcod != null) : !this.artcod.equals(other.artcod)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ProductosFavoritos{" + "usuari=" + usuari + ", tippro=" + tippro + ", artcod=" + artcod + '}';
    }
    
}
